package com.jojo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jojo.domain.Area;
import com.jojo.model.Result;
import com.jojo.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 地区业务模块控制层
 */
@Api("地区业务接口管理")
@RestController
@RequestMapping("admin/area")
public class AreaController {
    @Autowired
    private AreaService areaService;

    @ApiOperation("查询全国地区列表")
    @GetMapping("list")
    @PreAuthorize("hasAuthority('admin:area:list')")
    public Result<List<Area>> loadAllAreaList(){
        List<Area> list = areaService.queryAllAreaList();
        return Result.success(list);
    }

    /*@ApiOperation("多条件分页查询地址列表")
    @GetMapping("list")
    @PreAuthorize("hasAuthority('admin:area:page')")
    public Result<Page<Area>> loadAllAreaPage(@RequestParam Long current,
                                              @RequestParam Long size,
                                              @RequestParam(required = false) String addr){
        Page<Area> page = new Page<>(current,size);
        page = areaService.page(page,new LambdaQueryWrapper<Area>()
                .like(StringUtils.hasText(addr),Area::getAreaName,addr)
        );
        return Result.success(page);
    }*/
}
